-- Neovim配置 for DeepSpeed MOE + Qwen3-Coder
-- 安装依赖:
-- :PackerInstall
-- :CocInstall coc-pyright coc-tsserver

-- 插件管理器
local packer = require('packer')

-- 安装插件
packer.startup(function(use)
    -- 包管理器
    use 'wbthomason/packer.nvim'
    
    -- LSP配置
    use 'neovim/nvim-lspconfig'
    use 'williamboman/mason.nvim'
    use 'williamboman/mason-lspconfig.nvim'
    
    -- 代码补全
    use 'hrsh7th/nvim-cmp'
    use 'hrsh7th/cmp-nvim-lsp'
    use 'hrsh7th/cmp-buffer'
    use 'hrsh7th/cmp-path'
    use 'hrsh7th/cmp-vsnip'
    use 'hrsh7th/vim-vsnip'
    
    -- AI代码助手 (这里可以配置类似Continue的插件)
    use 'github/copilot.vim'
    
    -- 语法高亮
    use 'nvim-treesitter/nvim-treesitter'
    
    -- 文件浏览器
    use 'kyazdani42/nvim-tree.lua'
    
    -- 状态栏
    use 'nvim-lualine/lualine.nvim'
    
    -- 终端
    use 'voldikss/vim-floaterm'
    
    -- 主题
    use 'folke/tokyonight.nvim'
end)

-- 基本设置
vim.o.number = true
vim.o.relativenumber = true
vim.o.tabstop = 4
vim.o.softtabstop = 4
vim.o.shiftwidth = 4
vim.o.expandtab = true
vim.o.autoindent = true
vim.o.smartindent = true
vim.o.wrap = false
vim.o.clipboard = "unnamedplus"
vim.o.undofile = true
vim.o.backup = false
vim.o.writebackup = false

-- 颜色主题
vim.cmd[[colorscheme tokyonight]]

-- 插件配置
require('nvim-tree').setup()
require('lualine').setup()
require('mason').setup()
require('mason-lspconfig').setup()

-- LSP配置
local lspconfig = require('lspconfig')
lspconfig.pyright.setup{}
lspconfig.tsserver.setup{}
lspconfig.jsonls.setup{}

-- 代码补全配置
local cmp = require('cmp')
cmp.setup({
    snippet = {
        expand = function(args)
            vim.fn["vsnip#anonymous"](args.body)
        end,
    },
    mapping = {
        ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
        ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
        ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
        ['<C-e>'] = cmp.mapping(cmp.mapping.close(), { 'i', 'c' }),
        ['<CR>'] = cmp.mapping.confirm({ select = true }),
    },
    sources = cmp.config.sources({
        { name = 'nvim_lsp' },
        { name = 'buffer' },
    })
})

-- 快捷键
vim.keymap.set('n', '<leader>ff', ':NvimTreeToggle<CR>', {})
vim.keymap.set('n', '<leader>ft', ':FloatermToggle<CR>', {})
vim.keymap.set('n', '<leader>fm', ':Mason<CR>', {})
